package com.leonzx.base.service.system;

import com.leonzx.base.dao.system.ExcelTemplateDAO;
import com.leonzx.base.entity.system.ExcelTemplate;
import com.leonzx.base.entity.system.User;
import com.leonzx.base.service.BaseService;
import com.leonzx.base.utils.SQLUtils;
import com.leonzx.base.utils.UUIDUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

/**
 * @Author:张勇
 * @Description:
 * @Date: 2018-06-08 15:13
 */
@Service
public class ExcelTemplateService extends BaseService {
    @Autowired
    private ExcelTemplateDAO excelTemplateDAO;

    public List<ExcelTemplate> getAllBaseBjBjjj(ExcelTemplate excelTemplate) {

        Example example = new Example(User.class);
        Example.Criteria criteria = example.createCriteria();

        if (StringUtils.isNotBlank(excelTemplate.getName())) {
            criteria.andLike("name", SQLUtils.like(excelTemplate.getName()));
        }

        return excelTemplateDAO.selectByExample(example);
    }

    public ExcelTemplate getUserById(ExcelTemplate excelTemplate) {
        return excelTemplateDAO.selectOne(excelTemplate);
    }

    public void insert(ExcelTemplate excelTemplate) {
        excelTemplate.setId(UUIDUtils.getUUID());
        excelTemplate.setCreateTime(new Date());
        excelTemplateDAO.insert(excelTemplate);
    }

    public void update(ExcelTemplate excelTemplate) {
        excelTemplateDAO.updateByPrimaryKeySelective(excelTemplate);
    }
}
